<?php
	$sql="SELECT qldl_chi_tiet_dat_tour.MA_TOUR, COUNT( qldl_chi_tiet_dat_tour.MA_TOUR ),
			qldl_tour.HINH_ANH, qldl_tour.TEN_TOUR,
			qldl_tour.GIA, qldl_tour.TG_KHOI_HANH,qldl_tour.SO_NGAY,qldl_tour.SO_CHO 
			FROM qldl_chi_tiet_dat_tour
			inner join qldl_tour
			on qldl_chi_tiet_dat_tour.ma_tour=qldl_tour.ma_tour
			GROUP BY qldl_chi_tiet_dat_tour.MA_TOUR
			limit 0,3";
	$result=$mysqli->query($sql);
	while ($row=$result->fetch_array()){
		$songay = $row['SO_NGAY']-1;

		$date=strtotime($row['TG_KHOI_HANH']);
		$data =date('d-m-Y',$date);
		echo "<ul class='list-tour'>
				<li>
				<img src='admin/tour/upload/news/".$row['HINH_ANH']."'  width='180' height='150'/>
				<div class='info-tour'>
                <b><a href='index.php?id=chitiet&page=".$row['MA_TOUR']."'><font style='text-transform:uppercase'>".
				$row['TEN_TOUR']."</a></font></b><br />
				<font color='#FF0000' face='Tahoma, Geneva, sans-serif' style='font-weight:bold;font-size:13pt'>".
				number_format($row['GIA'],0,",",".")."&nbspVNĐ</font><br />
				<font style='font-size:13pt;'>
				<B>Khởi hành: </B>".$data."<br />
        		<B>Thời gian: </B>".$row['SO_NGAY']."&nbsp;ngày&nbsp". $songay ."&nbspđêm <BR />
        		<b>Số chỗ còn lại: </b> <font color='#FF0000' face='Tahoma, Geneva, sans-serif' style='font-weight:bold;font-size:13pt'>" .$row['SO_CHO']."</font><br>
				<B>Phương tiện: </B>";
		$sql_1=$mysqli->query("SELECT qldl_phuong_tien.TEN_PHUONG_TIEN
								FROM qldl_chi_tiet_phuong_tien
								INNER JOIN qldl_tour 
								ON qldl_tour .ma_tour=qldl_chi_tiet_phuong_tien.ma_tour
								INNER JOIN qldl_phuong_tien 
								ON qldl_chi_tiet_phuong_tien.ma_phuong_tien = qldl_phuong_tien.ma_phuong_tien
								WHERE qldl_tour .ma_tour = '".$row['MA_TOUR']."'");
		while($row=$sql_1->fetch_array()){
			echo $row['TEN_PHUONG_TIEN'];
			if($sql_1->num_rows == 1)
				echo".";
			else {
				echo",";
				echo"&nbsp;";
			}

		}
		echo "</font></div></li></ul><hr />";
  	}
?>